/*
https://leetcode.cn/problems/identify-the-largest-outlier-in-an-array/submissions/584376617/
100444. 识别数组中的最大异常值
*/
class Solution {
public:
    int getLargestOutlier(vector<int>& nums) {
        unordered_map<int,int>mp;
        int total=0;
        for(int x:nums){
            mp[x]++;
            total+=x;
        }
        int ans=-1008611;
        for(int x:nums){
            mp[x]--;
            if((total-x)%2==0&&mp[(total-x)/2]>0)
                ans=max(ans,x);
            ++mp[x];
        }
        return ans;
    }
};